#!/usr/local/bin/python3

import sys, time, os
from daemon import daemon
import httpserver
from utils import log, settings

class wxdaemon(daemon):
	def run(self):
		httpserver.run()

if __name__ == "__main__":

	daemon = wxdaemon(settings['tmpdir'] + 'daemon.pid')
	if len(sys.argv) == 2:
		if 'start' == sys.argv[1]:
			log.info('Starting')
			daemon.start()
			log.info('Started')
		elif 'stop' == sys.argv[1]:
			log.info('Stopping')
			daemon.stop()
			log.info('Stopped')
		elif 'restart' == sys.argv[1]:
			log.info('Restarting')
			daemon.restart()
			log.info('Restarted')
		else:
			log.error('Unknown command')
			sys.exit(2)
		sys.exit(0)
	else:
		print("Usage: %s start|stop|restart" % sys.argv[0])
		sys.exit(2)
